

package org.hive.hive;

import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class DisplayPictures extends Activity implements OnClickListener {
	private static ImageView img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display);
        getImages();
        img1=(ImageView)findViewById(R.id.imageView1);
        img1.setOnClickListener(this);
        img2=(ImageView)findViewById(R.id.imageView2);
        img2.setOnClickListener(this);
        img3=(ImageView)findViewById(R.id.imageView3);
        img3.setOnClickListener(this);
        img4=(ImageView)findViewById(R.id.imageView4);
        img4.setOnClickListener(this);
        img5=(ImageView)findViewById(R.id.imageView5);
        img5.setOnClickListener(this);
        img6=(ImageView)findViewById(R.id.imageView6);
        img6.setOnClickListener(this);
        img7=(ImageView)findViewById(R.id.imageView7);
        img7.setOnClickListener(this);
        img8=(ImageView)findViewById(R.id.imageView8);
        img8.setOnClickListener(this);
        img9=(ImageView)findViewById(R.id.imageView9);
        img9.setOnClickListener(this);
        img10=(ImageView)findViewById(R.id.imageView10);
        img10.setOnClickListener(this);
        img11=(ImageView)findViewById(R.id.imageView11);
        img11.setOnClickListener(this);
        img12=(ImageView)findViewById(R.id.imageView12);
        img12.setOnClickListener(this);
}
	public void getImages()
	{
		int[] img_ids = {R.id.imageView1,R.id.imageView2,R.id.imageView3,R.id.imageView4,R.id.imageView5,R.id.imageView6,R.id.imageView7,R.id.imageView8,R.id.imageView9,R.id.imageView10,R.id.imageView11,R.id.imageView12};
		//for ( int i =0 ; i < Global.takenPhotos.size();i++)
		Collection<photos> photoset = Global.takenPhotos.values();
		int i = 0;
		Global.imgviewtoidmapping = new HashMap();
		for (photos tempValue : photoset)
		{
			try{
				int photoid = tempValue.photoid;
				int albumid = tempValue.albumid;
				HttpClient hc = new DefaultHttpClient();
				HttpPost post = new HttpPost(Global.URL+"MobilePhotoDownload?userid="+Global.userid+"&albumid="+albumid+"&photoid="+photoid+"&isthumb=yes");

				HttpResponse rp = hc.execute(post);

				InputStream in = rp.getEntity().getContent();

				Bitmap bitmap = BitmapFactory.decodeStream(in);
				int width =bitmap.getWidth();
				System.out.println(width);
				in.close();
				Global.imgviewtoidmapping.put(new Integer(img_ids[i]), new Integer(photoid));
				ImageView img = (ImageView) findViewById(img_ids[i]);
				img.setImageBitmap(bitmap);
			
				i++;
				if (i == 12)
					break;
			}
			catch(Exception e){
				e.printStackTrace();
			}
			
		}
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent i;
		switch(v.getId())
		{
		case R.id.imageView1:
			Global.selected_photo_id = R.id.imageView1;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView2:
			Global.selected_photo_id = R.id.imageView2;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView3:
			Global.selected_photo_id = R.id.imageView3;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView4:
			Global.selected_photo_id = R.id.imageView4;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView5:
			Global.selected_photo_id = R.id.imageView5;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView6:
			Global.selected_photo_id = R.id.imageView6;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView7:
			Global.selected_photo_id = R.id.imageView7;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView8:
			Global.selected_photo_id = R.id.imageView8;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView9:
			Global.selected_photo_id = R.id.imageView9;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView10:
			Global.selected_photo_id = R.id.imageView10;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView11:
			Global.selected_photo_id = R.id.imageView11;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;
		case R.id.imageView12:
			Global.selected_photo_id = R.id.imageView12;
			Global.is_reco_photo_selected = false;
			i=new Intent(this,fullimages.class);
			startActivity(i);
			break;

	}
}
}
